stage.create_grid_overlay(50, 'greenyellow')
size = .3
planet = codesters.Sprite("mars", -200, -200)
planet.set_size(.4)
planet.collision_off()
stop1 = codesters.Sprite("codester", -100, -100)
stop1.set_size(size)
stop2 = codesters.Sprite("codester", 150, -100)
stop2.set_size(size)
stage.set_background("space")
sprite = codesters.Sprite("ufo")
sprite.set_size(0.4)
sprite.go_to(-200, -200)
sprite.pen_down()
sprite.glide_to(-100, -100)
def collision(sprite, hit_sprite):
hit_sprite.hide()
# add any other actions...
sprite.event_collision(collision)
sprite.set_speed(2)
t = codesters.Teacher()
glides = t.get_parameters_for_function('glide_to')
try:
tval1 = int(glides[-1][0])
dev_x = abs(150 - tval1)
except:
tval1 = "DNE"
dev_x = "DNE"
try:
tval2 = int(glides[-1][1])
dev_y = abs(-100 - tval2)
except:
tval2 = "DNE"
dev_y = "DNE"
dev = 50
t1 = TestObjective()
t1.add_success(dev_x<= dev and len(glides) >=2, "Great job!")
t1.add_failure(tval1 == "DNE" or len(glides) < 2, "There's the Codester! Now add a Glide To command.")
t1.add_failure(tval1 > 250 or tval1 < -250, "Oops! You moved your sprite off the stage!")
t1.add_failure(dev_x > dev and len(glides) >= 2, "Change your x-coordinate to get closer to the sprite!")
t2 = TestObjective()
t2.add_success(dev_y <= dev and len(glides) >= 2, "Great job!")
t2.add_failure(tval2 == "DNE" or len(glides) < 2, "There's the Codester! Now add a Glide To command.")
t2.add_failure(tval2 > 250 or tval2 < -250, "Oops! You moved your sprite off the stage!")
t2.add_failure(dev_y > dev and len(glides) >= 2, "Change your y-coordinate to get closer to the sprite!")
tester = TestManager()
tester.add_test_list([t1, t2])
tester.run_tests()
tester.display_first_feedback()
-
Run Code
-
Activity Submitted!
Submit Work
-
Next Activity
-
Stop Running Code
-
Show Chart
-
Show Console
-
Reset Code Editor
-
Codesters How To (opens in a new tab)